package com.itheima.dubbo.web;

import com.itheima.dubbo.HelloFace;
import com.itheima.dubbo.pojo.User;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:
 * @Version: V1.0
 */
@RestController
public class HelloController {


    //@DubboReference    //服务消费方注入helloFace
    //@DubboReference(timeout = 3000)    //超时时间
    //@DubboReference(version = "2.0.0")
    //@DubboReference(version = "2.0.0", loadbalance = "roundrobin")  //负载均衡默认是 random
    //@DubboReference(cluster = "failfast",version = "2.0.0", loadbalance = "roundrobin")  //负载均衡默认是 random
    @DubboReference(version = "2.0.0", check = false)  //启动时检查设置 false
    private HelloFace helloFace;


    @GetMapping("hello")
    public String hello(String name) {
        RpcContext.getContext().setAttachment("jwt", "123124312dfnsmfhjasdfh1231");
        return helloFace.hello(name);
    }

    @GetMapping("user")
    public User findByUsername(String username) {
        return helloFace.findByUsername(username);
    }

}
